﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Core.Primitives
{
    [Serializable]
    public class Matrix<T>
    {
        private T[,] m_values;
        public T[,] Values
        {
            get { return m_values; }
            set { m_values = value; }
        }

        public int Height
        {
            get
            {
                return m_values.GetLength(0);
            }
        }
        public int Width
        {
            get
            {
                return m_values.GetLength(1);
            }
        }
        public IntSize Size
        {
            get
            {
                return new IntSize(m_values.GetLength(1), m_values.GetLength(0));
            }
        }

        public Matrix(int height, int width)
        {
            m_values = new T[height, width];
        }

        public T this[int row, int column]
        {
            get
            {
                if (row < 0 || column < 0 || row >= Height || column >= Width)
                    return default(T);

                return m_values[row, column];
            }

            set
            {
                if (row < 0 || column < 0 || row >= Height || column >= Width)
                    throw new Exception("Invalid position");

                m_values[row, column] = value;
            }
        }
        public T this[IntPosition pos]
        {
            get
            {
                return this[pos.Row, pos.Column];
            }
            set
            {
                this[pos.Row, pos.Column] = value;
            }
        }
    }
}
